package com.example.homework.service;

import org.springframework.stereotype.Service;
import com.example.homework.model.Teacher;

import java.util.List;

@Service
public class TeacherService {

    private List<Teacher> teachers;

    public void addTeacher(Teacher teacher) {
        teachers.add(teacher);
    }


    public List<Teacher> getAllTeachers() {
        return teachers;
    }


    public void deleteTeacher(String id) {
        teachers.removeIf(teacher -> teacher.getId().equals(id));
    }


    public void updateTeacher(Teacher teacher) {
        for (Teacher t : teachers) {
            if (t.getId().equals(teacher.getId())) {
                t.setName(teacher.getName());
                t.setSubject(teacher.getSubject());
                break;
            }
        }
    }
}
